package com.example.primarycalculator2;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.widget.ListView;
import android.widget.TextView;

import com.ashokvarma.bottomnavigation.BottomNavigationBar;
import com.ashokvarma.bottomnavigation.BottomNavigationItem;
import com.ashokvarma.bottomnavigation.ShapeBadgeItem;
import com.ashokvarma.bottomnavigation.TextBadgeItem;

import org.litepal.LitePal;

import java.util.List;

public class ErrorActivity extends AppCompatActivity implements BottomNavigationBar.OnTabSelectedListener{
    BottomNavigationBar bottomNavigationBar;
    @Nullable
    TextBadgeItem numberBadgeItem;
    @Nullable
    ShapeBadgeItem shapeBadgeItem;
    int lastSelectedPosition = 1;



    public static final String TAG="ErrorActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        Log.d(TAG, "onCreate: ");

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_error);


        bottomNavigationBar = findViewById(R.id.bottom_navigation_bar_error);
        bottomNavigationBar.setTabSelectedListener(this);
        refresh();


        List<Problem> problems= LitePal.findAll(Problem.class);

        AnswerAdapter adapter=new AnswerAdapter(ErrorActivity.this,R.layout.answer_item, problems);
        ListView listView=findViewById(R.id.error_view);
        listView.setAdapter(adapter);

    }


    @SuppressLint("WrongConstant")
    private void refresh() {

        bottomNavigationBar.clearAll();
        numberBadgeItem = new TextBadgeItem()
                .setBorderWidth(4)
                .setBackgroundColorResource(R.color.blue)
                .setText("" + lastSelectedPosition)
                .setHideOnSelect(false);
        shapeBadgeItem = new ShapeBadgeItem()
                .setShape(5)
                .setShapeColorResource(R.color.teal)
                .setGravity(Gravity.TOP | Gravity.END)
                .setHideOnSelect(false);
        numberBadgeItem.toggle();
        shapeBadgeItem.toggle();
        bottomNavigationBar.setMode(2);
        bottomNavigationBar
                .addItem(new BottomNavigationItem(R.drawable.ic_home_white_24dp, "home").setActiveColorResource(R.color.orange).setBadgeItem(numberBadgeItem))
                .addItem(new BottomNavigationItem(R.drawable.ic_book_white_24dp, "error book").setActiveColorResource(R.color.teal))
                .addItem(new BottomNavigationItem(R.drawable.ic_github_circle_white_24dp, "user").setActiveColorResource(R.color.blue).setBadgeItem(shapeBadgeItem))
                .setFirstSelectedPosition(lastSelectedPosition > 2 ? 2 : lastSelectedPosition)
                .initialise();
    }



    @Override
    public void onTabSelected(int position) {
        lastSelectedPosition = position;
        Log.d(TAG, "onTabSelected: "+lastSelectedPosition);
        switch (lastSelectedPosition){
            case 0:
                Intent intent=new Intent(ErrorActivity.this,MainActivity.class);
                startActivity(intent);
                break;
            case 1:
                break;
            case 2:
                Intent intent2=new Intent(ErrorActivity.this,UserActivity.class);
                startActivity(intent2);
                break;
        }

    }

    @Override
    public void onTabUnselected(int position) {

    }

    @Override
    public void onTabReselected(int position) {

    }





}